package com.tj.collection.db.dao.impl;

import com.fqgj.common.api.Page;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.datasource.DataSource;
import com.tj.collection.db.dao.ClCallDurationDao;
import com.tj.collection.db.entity.ClCallDurationEntity;
import com.tj.collection.db.entity.business.ClCallInfoEntity;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: Karl
 * Date: 2020-01-16
 * Time: 10:43:46.798
 */

@Repository
public class ClCallDurationDaoImpl extends AbstractBaseMapper<ClCallDurationEntity> implements ClCallDurationDao {

    @Override
    public List<ClCallDurationEntity> selectCallDurationByParams(Map<String, Object> params) {
        if (!params.containsKey("deleted")) {
            params.put("deleted", 0);
        }
        if (params.containsKey("page")) {
            Page page = (Page) params.get("page");
            page.setTotalCount(this.countCallDurationByParams(params));
        }
        return getSqlSession().selectList(this.getStatement("selectCallDurationByParams"), params);
    }

    @Override
    public Integer countCallDurationByParams(Map<String, Object> params) {
        if (!params.containsKey("deleted")) {
            params.put("deleted", 0);
        }
        return getSqlSession().selectOne(this.getStatement("countCallDurationByParams"), params);
    }

    @Override
    public List<ClCallDurationEntity> selectCallDurationByCollectionNo(String collectionNo, String mobile, String startTime, String endTime) {
        Map<String, Object> params = new HashMap<>();
        params.put("collectionNo", collectionNo);
        params.put("mobile", mobile);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        return this.selectCallDurationByParams(params);
    }

    @Override
    public List<ClCallDurationEntity> selectWaitConvertCallDurationList(Page page) {
        if (page == null) {
            return null;
        }
        Map<String, Object> params = new HashMap<>();
        params.put("page", page);
        return getSqlSession().selectList(this.getStatement("selectWaitConvertCallDurationList"), params);
    }

    @Override
    public List<ClCallInfoEntity> selectCallDurationInfoList(Map<String, Object> params, Page page) {
        if (page == null) {
            return null;
        }
        if (page != null) {
            page.setTotalCount(countCallDurationInfo(params));
            params.put("page", page);
        }
        return getSqlSession().selectList(this.getStatement("selectCallDurationInfoList"), params);
    }

    private Integer countCallDurationInfo(Map<String, Object> params) {
        return getSqlSession().selectOne(this.getStatement("countCallDurationInfo"), params);
    }
}